package com.dd.common.response;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 响应报文枚举
 */
@AllArgsConstructor
@NoArgsConstructor
public enum ResultCode implements IResultCode, Serializable {

    SUCCESS("00000", "操作成功"),
    USER_LOGIN_ERROR("A2000", "用户未登录"),
    USER_NOT_EXIST("A2001", "用户不存在"),

    USER_ACCOUNT_EXIT("A2003","用户账户已经存在"),

    USERNAME_OR_PASSWORD_ERROR("A2004", "用户名或密码错误"),
    USERNAME_NOT_EXIT("A2005", "用户不存在"),

    USER_AUTH_ERROR("A2006","用户权限不足"),

    INVALID_TOKEN("B3000", "登录已过期,请重新登录"),

    FILE_UPLOAD_FILE("B3001","文件已经上传"),


    FILE_POINT_DOWN_ERROR("B3002","分片文件下载失败"),


    FILE_UPLOAD_ERROR("B3003","文件上传失败"),
    FILE_CHUNKS_MERGE__ERROR("B3004","分片文件合并失败"),
    SHARE_FILE_CANCEL("B3005","分享的文件不存在"),
    SHARE_FILE_TIME("B3006","文件链接已经过期"),

    FILE_DELETE__ERROR("B3005","文件删除失败"),

    PARAM_ERROR("C4000", "请求参数错误"),


    RESOURCE_NOT_FOUND("C4001", "请求资源为空"),
    PARAM_IS_NULL("C4002", "请求必填参数为空"),
    SYSTEM_EXECUTION_ERROR("D5000", "系统执行出错"),
    SYSTEM_REQUEST_METHOD_NOT_SUPPOSE("D5001","请求方式错误"),
    SYSTEM_EXECUTION_TIMEOUT("D5002", "系统执行超时");


    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    private String code;

    private String msg;

    @Override
    public String toString() {
        return "{" +
                "\"code\":\"" + code + '\"' +
                ", \"msg\":\"" + msg + '\"' +
                '}';
    }


    public static ResultCode getValue(String code){
        for (ResultCode value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return SYSTEM_EXECUTION_ERROR; // 默认系统执行错误
    }
}